home *** CD-ROM | disk | FTP | other *** search
- /*
- ***********************************************************************
- *
- * FlightWindow
- * a live (animated) window that displays the FlightView and tells it to move on
- *
- ***********************************************************************
- */
-
- #pragma once
-
- #include "ImageViews.h"
-
- // A more optimized version of a generic ThreeDView
- class ThreeDProjector_PeriodicMap;
- class FlightView : public ThreeDView<ThreeDProjector_PeriodicMap>
- {
- virtual void prepaint(void); // Draw the sky (as a background image)
- public:
- FlightView(const ElevationMap& elev_map, const ViewerPosition& viewer_pos,
- const ProjectionParameters& projection_parms)
- : ThreeDView<ThreeDProjector_PeriodicMap>(elev_map,viewer_pos,projection_parms) {}
- };
-
-
- // An utility class to help us count frames
- class StopWatch
- {
- int mark_counter; // Counts marks (say, drawn frames)
- int time_started; // Tick counter when the StopWatch was last started
- int time_stopped; // Tick counter when the StopWatch was stopped, or 0 if it is running
- public:
- StopWatch(void) : mark_counter(0), time_started(0), time_stopped(0) {}
- int operator ++ (void) { return mark_counter++; }
- void start(void) { mark_counter = 0; time_started = TickCount(); time_stopped = 0;}
- void stop(void) { time_stopped = TickCount(); }
- int marks_per_sec(void) const;
- };
- // A window that displays FlightView and does some
- // animation and key/mouse handling
- class FlightWindow : public ScreenWindow
- {
- class ViewerAnim: public ViewerPosition
- {
- const int sup_xe;
- const int sup_ye;
- int clip(const int x, const int sup_x) { return x < 0 ? x + sup_x : x >=sup_x ? x-sup_x: x; }
- public:
- ViewerAnim(const ScreenRect& rect);
- void move_hor(const int incr) { xe = clip(xe+incr, sup_xe); }
- void move_ver(const int incr) { ye = clip(ye+incr, sup_ye); }
- void stir(void); // move things a little
- };
- ViewerAnim viewer;
-
- class ProjAnim : public ProjectionParameters
- {
- Boolean clip(int& var, const int var_min, const int var_max)
- { if( var > var_max ) return var = var_max, FALSE;
- else if( var < var_min ) return var = var_min, FALSE;
- else return TRUE; }
- public:
- ProjAnim(const ScreenRect& rect)
- : ProjectionParameters(rect,226,83) { Ov = 75; }
- void climb(const int incr) { ze += incr; clip(ze,64,512); }
- void zoom(const int incr) { beta += incr; clip(beta,32,128); }
- void move_horizon(const int incr) { Ov += incr; clip(Ov,1,v_sup-1); }
- };
-
- ProjAnim proj_parameters;
-
- FlightView view_buffer;
-
- Boolean is_flying;
- StopWatch frame_counter; // Counts frames drawn
-
- virtual void draw(void); // It is this function that really draws smth
-
- protected:
-
- // Commencing and terminating the flight
- void start_flight(void);
- void stop_flight(void);
- void animate(void); // Usually called within draw()
-
- Boolean handle_mouse_down(const EventRecord& the_event, WindowPtr where_window, short window_part);
- Boolean handle_key_down(const EventRecord& the_event); // Handles key_down & auto_key events
- // Track the mouse clicked in content
- // and move the plane as the mouse (still down) moves
- Boolean track_mouse(Point mouse_down_pt);
-
- const PixMapHandle get_pixmap(void) const { return view_buffer.get_pixmap(); }
- // virtual void destroy_it(void); // A virtual window destructor
- virtual void setup_color_env(OffScreenBuffer& offscreen_buffer);
- Boolean was_QD_optimized; // Just an informational flag to see how sucessful my color
- // worlds negotiations were
-
- public:
- FlightWindow(const ElevationMap& elev_map, const int wind_id);
-
- // This constructor is similar to the one above, but works
- // in cases when the view_buffer dimensions aren't the same
- // as those of the on-screen window (and differ by a factor
- // of two, say). This is the case when the onscreen window
- // is way to big to buffer it offscreen (and some blockiness
- // due to blow-up during the blitting can be tolerated)
- FlightWindow(const ElevationMap& elev_map, const int wind_id,ScreenRect buffer_rect);
-
- virtual Boolean handle_null_event(const long event_time);
- void init(void); // post-constructor
- };
-
- // A flight window for the whole screen
- class FullFlightWindow : public FlightWindow
- {
- const int normal_menu_bar_height; // saved while flying
- virtual void destroy_it(void); // A virtual window destructor
- virtual void draw(void); // It is this function that really draws smth
- virtual void setup_color_env(OffScreenBuffer& offscreen_buffer);
- public:
- FullFlightWindow(const ElevationMap& image_map, const int wind_id);
- };
-